package com.cms.recursoshumanos.ui.principal;

import com.cms.recursoshumanos.cache.UserInfoCache;
import com.cms.recursoshumanos.component.base.CustomButtonColored;
import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.container.ForegroundManager;
import com.cms.recursoshumanos.container.TwoColumnFieldManager;
import com.cms.recursoshumanos.engine.ScreenEngine;
import com.cms.recursoshumanos.handler.VacacionesMainScreenHandler;
import com.cms.recursoshumanos.ui.RecursosHumanosScreen;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.WLANInfo;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BorderFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class PantallaVacacionesMainScreen extends RecursosHumanosScreen
{
    /**
     * Creates a new MyScreen object
     */
	//static Utileria tools = new Utileria();
	private CustomButtonColored boton_consult_cant_vacaciones, 
								boton_consult_info_vacaciones,
								boton_solicitar_planilla_vacaciones;
	
	public static PantallaVacacionesMainScreen instance = null;
	
	VerticalFieldManager vfm;
	LabelField lblInfoVacaciones;
	
	public static PantallaVacacionesMainScreen getInstance()
	{
		if (instance == null)
		{
			return new PantallaVacacionesMainScreen();
		}
		else
		{
			return instance;
		}
	}
	public PantallaVacacionesMainScreen() 
	{
		super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT );
		
		setear_componenetes();
		
	}
	
	public boolean isConected()
	{
		 if(CoverageInfo.isOutOfCoverage())
         {
			 if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
			 {
				 return true;
			 }
			 else 
			 {
				 return false;
			 }
         }
		 else
		 { 
			 return true; 
		 }             
	}
	
	private void setear_componenetes() 
	{
		setTitle("Principal Vacaciones");
		ForegroundManager foreground = new ForegroundManager();
		
		vfm = new VerticalFieldManager(USE_ALL_WIDTH| FIELD_HCENTER | FIELD_VCENTER);
		
        TwoColumnFieldManager twoColumnManager = new TwoColumnFieldManager( Display.getWidth() / 3, USE_ALL_WIDTH | DrawStyle.VCENTER );
        twoColumnManager.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager.setMargin( 10, 10, 10, 10 );
        twoColumnManager.setPadding( 6, 6, 6, 6 );
        
        lblInfoVacaciones = new LabelField("Escoja una Opcion", 
				DrawStyle.HCENTER | Field.FIELD_HCENTER);
		lblInfoVacaciones.setFont(font_italic_7);
		
        
		boton_consult_cant_vacaciones = new CustomButtonColored("Cantidad de Vacaciones", 
																	ButtonField.CONSUME_CLICK | 
																	FIELD_HCENTER | 
																	DrawStyle.HCENTER |
																	USE_ALL_WIDTH, 
																	Constant.COLOR_BUTTON_FOCUS); 
		boton_consult_cant_vacaciones.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			VacacionesMainScreenHandler handler = new VacacionesMainScreenHandler();
	   			handler.getVacacionesDias(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   					UserInfoCache.getInstance().getUsuario().getPassword());
	       	} 
		}); 
        
		boton_solicitar_planilla_vacaciones = new CustomButtonColored("Solicitar Planilla",
																		ButtonField.CONSUME_CLICK | 
																		FIELD_HCENTER | 
																		DrawStyle.HCENTER |
																		USE_ALL_WIDTH, 
																		Constant.COLOR_BUTTON_FOCUS); 
		boton_solicitar_planilla_vacaciones.setChangeListener(new FieldChangeListener() 
		{
			public void fieldChanged(Field field, int context) 
		   	{ 
				ScreenEngine.getInstance().goPlanillaVacaciones();
		   	} 
		}); 
		
        boton_consult_info_vacaciones = new CustomButtonColored("Informacion de Vacaciones",ButtonField.CONSUME_CLICK | 
																	FIELD_HCENTER | 
																	DrawStyle.HCENTER |
																	USE_ALL_WIDTH, 
																	Constant.COLOR_BUTTON_FOCUS); 
        boton_consult_info_vacaciones.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ScreenEngine.getInstance().goPantallaInfoVacaciones();
	       	} 
		}); 
        
        Field separator = new SeparatorField();
        separator.setMargin( 2, 0, 2, 0 );
        
        vfm.add(lblInfoVacaciones);
        vfm.add(separator);
        
        vfm.add( boton_consult_cant_vacaciones );
        vfm.add( boton_solicitar_planilla_vacaciones );
        vfm.add( boton_consult_info_vacaciones );
        
        twoColumnManager.add(vfm);
        
        foreground.add( twoColumnManager );
        add( foreground );
			
	}
	
	
}
